﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BaddiesEditor.CustomComponent
{
    /// <summary>
    /// Form for warning messages to the user. Use instead of ErrorForm when we want a ok and cancel buttons.
    /// </summary>
    public partial class WarningForm : Form
    {
        /// <summary>
        /// Event handler for when we click the ok button.
        /// </summary>
        private EventHandler acceptButtonHandler;

        /// <summary>
        /// Event handler for when we click the cancel button.
        /// </summary>
        private EventHandler cancelButtonHandler;

        /// <summary>
        /// Initializes a new instance of the WarningForm class.
        /// </summary>
        /// <param name="acceptButtonHandler">Event handler for the ok button.</param>
        /// <param name="cancelButtonHandler">Event handler for the cancel button.</param>
        public WarningForm(EventHandler acceptButtonHandler, EventHandler cancelButtonHandler)
        {
            this.InitializeComponent();

            this.acceptButtonHandler += acceptButtonHandler;
            this.cancelButtonHandler += cancelButtonHandler;
        }

        /// <summary>
        /// Sets the warning message of the WarningForm.
        /// </summary>
        /// <param name="msg"> Message to show.</param>
        public void SetWarningMsg(string msg)
        {
            this.warningText.Text = msg;
        }

        /// <summary>
        /// Called when the OK button is clicked.
        /// </summary>
        /// <param name="sender">Class that calls the handler.</param>
        /// <param name="e">Arguments of the call.</param>
        private void Okbutton_Click(object sender, EventArgs e)
        {
            this.Close();
            if (this.acceptButtonHandler != null)
            {
                this.acceptButtonHandler(this, null);
            }            
        }

        /// <summary>
        /// Called when the Cancel button is clicked.
        /// </summary>
        /// <param name="sender">Class that calls the handler.</param>
        /// <param name="e">Arguments of the call.</param>
        private void CancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
            if (this.cancelButtonHandler != null)
            {
                this.cancelButtonHandler(this, null);
            }            
        }

        /// <summary>
        /// Called when the form loads.
        /// </summary>
        /// <param name="sender">Class that calls the handler.</param>
        /// <param name="e">Arguments of the call.</param>
        private void WarningForm_Load(object sender, EventArgs e)
        {
            // Set the text width so it doesn't overflow.
            this.warningText.MaximumSize = new Size(this.Width - (2 * this.warningText.Location.X), 0);
        } 
    }
}
